package com.ljh.cloudmusic.controller;

import com.ljh.cloudmusic.model.Music;
import com.ljh.cloudmusic.model.MusicWithFavorite;
import com.ljh.cloudmusic.service.MusicService;
import com.ljh.cloudmusic.utils.ResponseBodyMessage;
import jakarta.servlet.http.HttpServletRequest;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.UrlResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.core.io.Resource;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.List;

/**
 * @author: Themberfue
 * @date: 2025/3/8 14:27
 * @description:
 */
@RestController
@RequestMapping("/music")
public class MusicController {
    @Value("${music.local.path}")
    private String SAVE_PATH;

    @Autowired
    MusicService musicService;
    @RequestMapping("/uploadMusic")
    public ResponseBodyMessage<Boolean> uploadMusic(@RequestParam("files") List<MultipartFile> files, HttpServletRequest request) throws IOException {
        return musicService.uploadMusic(files, request);
    }

    @RequestMapping("/getMusic")
    public ResponseEntity<Resource> getMusic(@RequestParam String path,HttpServletRequest request) throws IOException {
        return musicService.getMusic(path, request);
    }
    @RequestMapping("/getCover")
    public ResponseEntity<Resource> getCover(@RequestParam String path) {
        return musicService.getCover(path);
    }

    @RequestMapping("/getMusicList")
    public ResponseBodyMessage<List<MusicWithFavorite>> getMusicList(HttpServletRequest request) {
        return musicService.getMusicList(request);
    }

    @RequestMapping("/deleteMusic")
    public ResponseBodyMessage<Boolean> deleteMusic(@RequestParam List<Integer> ids) {
        return musicService.deleteMusic(ids);
    }

    @RequestMapping("/searchMusic")
    public ResponseBodyMessage<List<MusicWithFavorite>> searchMusic(@RequestParam String musicName, HttpServletRequest request) {
        return musicService.searchMusic(musicName, request);
    }
}
